package demo2;

//牛客网:神奇数
import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        //System.out.println(check(14));
        int a = in.nextInt();
        int b = in.nextInt();
        int count = 0;
        for(int i = a; i<=b; i++) {
            if(check(i)) {
                count++;
                //System.out.println(i);
            }
        }
        System.out.println(count);
    }

    public static boolean check(int u) {
         String s = Integer.toString(u);
         int n = s.length();
         for(int i = 1; i<n; i++) {
            char c1 = s.charAt(i);
            for(int j = 0; j<i; j++) {
                char c2 = s.charAt(j);
                int a = (c1-'0')*10 + (c2-'0');
                int b = (c2-'0')*10 + (c1-'0');
                if(a>10 && check2(a)) {
                    //System.out.println(a);
                    return true;
                }
                if(b>10 && check2(b)) {
                    //System.out.println(b);
                    return true;
                }
            }
         }
        return false;
    }

    public static boolean check2(int u) {
        int q = (int)Math.sqrt(u);
        for(int i = 2; i<=q; i++) {
            if(u%i==0) {
                return false;
            }
        }
        return true;
    }
}